package com.lanou.projecta.tv;


import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lanou.projecta.R;

import java.util.List;

/**
 * Created by dllo on 16/1/11.
 */
public class TvFragment extends Fragment {
    private RequestQueue queue;
    private ListView listView;
    private BaseTv baseTv;
    private List<BaseTv.VideoListEntity> baseTv1;
    private TvFragmentBaseAdapter adapter;
    private String url = "http://c.3g.163.com/nc/video/home/0-10.html";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tv, null);
        listView = (ListView) view.findViewById(R.id.tv_listview);
        queue = Volley.newRequestQueue(getActivity());

        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                baseTv = gson.fromJson(response, BaseTv.class);
                baseTv1 = baseTv.getVideoList();
                adapter = new TvFragmentBaseAdapter(baseTv1, getActivity());

                listView.setAdapter(adapter);


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        queue.add(request);
        return view;
    }
}
